!function() {
    var t = ["knowledgebase/(DSM|DSMUC|Surveillance|SRM|Mobile)/(help|tutorial|video)"]
      , e = null
      , n = null;
    function o(e, n) {
        return console.log("isDoRouterPage", e, n),
        !t.some((function(t) {
            var o = new RegExp(t,"i");
            return o.test(n) && o.test(e)
        }
        ))
    }
    function a(t) {
        var e = $(this)
          , n = e.attr("href")
          , o = e.attr("target");
        !(!n || /^http(s)?:\/\//.test(n) || /^javascript:/.test(n) || /^mailto:/.test(n) || /^#/.test(n) || /^img(.*?)(jpg|png|gif)/.test(n) || "string" == typeof o && ("_blank" == o || "_new" == o) || e.is("[data-toggle], [data-gallery]")) ? (t.preventDefault(),
        i(n)) : /^#/.test(n) && t.preventDefault()
    }
    function i(t) {
        if (history.pushState) {
            var e = o(t, location.href);
            window.history.pushState({
                page: t
            }, "", t),
            c(e),
            SYNO_WEB.lastUrl = t
        } else
            window.location.href = t
    }
    function r(t) {
        console.log("replaceUrl", t);
        var e = !0
          , n = new RegExp("^" + window.location.origin);
        /^http(s)?:\/\//.test(t) && !n.test(t) && (e = !1),
        history.replaceState && e ? history.replaceState({
            page: t
        }, "", t) : location.href != t && (location.href = t)
    }
    function l(t) {
        t.length && r(location.href.split("#")[0] + "#" + t)
    }
    function s(t) {
        console.log("popUrlHandler", t);
        var e = o(location.href, SYNO_WEB.lastUrl);
        e ? (c(e),
        SYNO_WEB.lastUrl = location.href) : SYNO_WEB.mainBody.trigger("pageLoaded")
    }
    function c(t) {
        1 == t ? d() : SYNO_WEB.mainBody.trigger("pageLoaded")
    }
    function d() {
        SYNO_WEB.mainBody.css({
            opacity: 0
        }),
        SYNO_WEB.scrollTo(0, {
            speed: 0
        }),
        e && e.abort();
        var t = location.pathname;
        location.search ? t = t + location.search + "&ajax=1" : t += "?ajax=1",
        e = $.ajax({
            url: t,
            type: "get",
            dataType: "html"
        }).done((function(t, e, o) {
            !function(t, e) {
                var o = $("head")
                  , a = $("<div>").html(t);
                if (0 < a.find("synoredirect").length) {
                    console.log(a.find("synoredirect").text());
                    var i = a.find("synoredirect").text();
                    return r(i),
                    window.location.href = i,
                    !1
                }
                if (0 < a.find("synometa").length) {
                    var l = $('meta[name="keywords"]');
                    SYNO_WEB.mainBody.removeClass().addClass(a.find("synometa").attr("section")),
                    $("title").text(a.find("synometa").attr("title")),
                    $('meta[name="description"]').attr("content", a.find("synometa").attr("descr")),
                    l.length && l.attr("content", a.find("synometa").attr("keywords"))
                }
                a.find("link").each((function() {
                    var t = $(this).attr("href");
                    0 == o.find('link[href="' + t + '"]').length && $("<link>").appendTo(o).attr({
                        rel: "stylesheet",
                        href: t
                    })
                }
                ));
                var s = a.find("style");
                if (s.length > 0) {
                    var c = s[0].innerHTML;
                    if (c) {
                        var d = document.querySelector("head style");
                        d && (d.innerHTML = c)
                    }
                }
                window.dsygno && window.dsygno.goTop && window.dsygno.goTop.showOrHide();
                a.find("synometa").remove(),
                a.find("link").remove(),
                a.find("script").attr("nonce", n),
                $("body > #tiptip_holder, body > .select2-container--open, body > .autocomplete-suggestions").remove(),
                SYNO_WEB.mainBody.html(a.html()),
                e && e()
            }(t, (function() {
                SYNO_WEB.mainBody.css({
                    opacity: 1
                }).trigger("pageLoaded")
            }
            ))
        }
        )).fail((function(t, e, n) {
            console.log("Ajax error: " + t.status),
            location.reload()
        }
        ))
    }
    function f(t, e) {
        var n = window.location.pathname.replace(/\?$/, "");
        (e = e || location.hash).length && "#" != e[0] && (e = "#" + e),
        "string" == typeof t ? n = [n, t].join("?") : "object" == typeof t && (n = [n, $.param(t)].join("?")),
        r(n += e)
    }
    function p(t, e) {
        return $.ajax({
            dataType: "script",
            url: t,
            success: e,
            scriptAttrs: {
                nonce: n
            }
        })
    }
    window.history.replaceState({
        page: window.location.href
    }, "", window.location.href),
    SYNO_WEB.router = d,
    SYNO_WEB.pushUrl = i,
    SYNO_WEB.replaceUrl = r,
    SYNO_WEB.replaceHash = l,
    SYNO_WEB.updateQueryString = f,
    SYNO_WEB.getScript = p,
    $("body").on("click", "a", a),
    window.onpopstate = s,
    n = $("meta[name=nonce]").attr("content")
}();
